package com.lhf.fvscore.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * <p></p>
 *
 * @author lhf
 * @since 2020/10/22 15:34
 */
@Component
@Aspect
public class LoggerAop {
    private static final Logger logger = LoggerFactory.getLogger(LoggerAop.class);

    @Pointcut(value = "@annotation(com.lhf.fvscore.annotation.Logging)")
    public void pointcut() {
    }

    @AfterReturning(pointcut = "pointcut()", returning = "obj")
    public void after(JoinPoint jp, Object obj) {
        Signature signature = jp.getSignature();
        MethodSignature ms = (MethodSignature) signature;
        Method method = ms.getMethod();

        logger.info("当前请求接口:{},方法:{}", signature.getName(), method.getName());
        Object[] args = jp.getArgs();
        logger.info("请求参数为:{}" + Arrays.toString(args));

    }

}
